﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Web.Mvc;
using Projectmanagement.Utl;
using ProjectManagement.Models;
using Projectmanagement.Entity;

namespace Projectmanagement.Controllers
{
    [RoleRequired]
    public class MemberController : Controller
    {
        [GridAction]
        public ActionResult _SelectIndex(int? conferenceid)
        {
            return View(new GridModel(DQ.GetMembers(conferenceid).OrderBy(o=>o.Name)));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _SaveAjaxEditing(int id, int? conferenceid)
        {
            var item = CH.GetDataByID<Member>(id);
            if (TryUpdateModel(item))
            {
                CH.Edit<Member>(item);
            }
            return View(new GridModel(DQ.GetMembers(conferenceid)));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _InsertAjaxEditing(int? conferenceid)
        {
            var item = new Member();

            if (TryUpdateModel(item))
            {
                item.ProjectID = conferenceid;
                CH.Create<Member>(item);
            }
            return View(new GridModel(DQ.GetMembers(conferenceid)));
        }

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _DeleteAjaxEditing(int id, int? conferenceid)
        {
            CH.Delete<Member>(id);
            return View(new GridModel(DQ.GetMembers(conferenceid)));
        }

        [HttpPost]
        public ActionResult getmembers(int projectId)
        {
            var data = Employee.GetAvailbleMembers(projectId);
                //CH.DB.Members.Where(x => x.ProjectID == projectId).ToList();
            return View(data);
        }

    }
}
